// tools1.gp version 0.1

KnapLat(a,t)=
{
 \\ return a Knapsack lattice with public key a=(a1,...,an) and target t
 \\ the output matrix is given in a form suitable for use with qflll
 \\ it is a transposed matrix of the one seen in the lecture (Ph. Elbaz-Vincent).

 local(n,m);

 if((type(a)!="t_VEC") && (type(a)!="t_COL"), error("*** KnapLat: first argument should be a (row or column) vector"));
 if((type(t)!="t_INT"),error("*** KnapLat: second argument should be an integer."));

 n=length(a);

 m=matid(n+1); \\ initialise the (n+1)x(n+1) identity matrix
 
 for(i=1,n, m[n+1,i]=a[i]);

 m[n+1,n+1]=-t;

 return(m);
}

addhelp(KnapLat,"KnapLat(a,t): generate a Knapsack lattice corresponding to the (row or column) vector a and the (integer) target t. The output is compatible with the format of qflll.");

